%% Simulate the finite-sample distribution of the PIT statistics

function cov_stat_sim = simulate_cov_stat_distribution(N, finite_dist_sim)
% INPUT: N, number of simulated sample finite_dist_sim
% OUTPUT: simulated coverage statistics cov_stat_sim

    % Simulate T samples of N Bernoulli(0.8) trials
    p = 0.8;
    cov_stat_sim = zeros(finite_dist_sim, 1);

    for t = 1:finite_dist_sim
        % Simulate N draws from Bernoulli(0.8)
        X = binornd(1, p, N, 1);
        % Compute the statistic S = (bar_X - 0.8)^2
        cov_stat_sim(t) = (mean(X) - p)^2;
    end

end
